package com.atguigu.gulimail.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Guo 2022/10/19 15:12:56
 */
@Configuration
public class MyRedissonConfig {

    /**
     * 所有对Redisson的使用都是通过RedissonClient对象
     * destroyMethod="shutdown"在spring bean回收后释放资源
     * @return
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() throws Exception{
        // 1、创建配置
        // Redis url should start with redis:// or rediss:// (for SSL connection)
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://43.138.126.232:6379")
                .setPassword("5&C!V5Ud%kzPNt6s");

        // 2、根据Config创建出RedissonClient实例
        return Redisson.create(config);
    }

}
